/**
 * 用户API接口
 */
import { v1 as uuid } from 'uuid'
import api from '@/api/request'

let domain = ''

export const user = {
  uuid: uuid()
}
//获取UUID
export const getUUID = function () {
  user.uuid = uuid()
  return `${api.domain}api/v2/user/captcha?uuid=${user.uuid}&_t=${Date.now()}`
}

// 退出登录
export const logout = function (token) {
  return api.post(`${domain}api/user/logout`, {
    data:{token,},
    showLoading: true
  })
}

// 获取用户状态
export const getUserState = function () {
  return api.get(`${domain}api/v2/individual/user/individualState`, {cancel:false})
}

// 获取用户状态
export const editNickname = function (data) {
  return api.post(`${domain}api/v2/individual/editName`, {
    data
  })
}

// 上传用户头像
export const uploadHeader = function (data) {
  return api.post(`${domain}api/v2/individual/upload/header`, {
    data,
    showLoading: true
  })
}

// 生成RSA公钥接口
export const getRsaPublicKey = function (success) {
  api.get(`${domain}api/v2/user/genRsaPublicKey`, {showLoading:true}).then(res=>{
    if(res.rst == api.SUCCESS){
      success && success(res.data)
    }
  })
}

// 上传用户头像
export const changePwd = function (data) {
  return api.post(`${domain}api/v2/user/changePwd`, {
    data,
    showLoading: true
  })
}

// 提交身份认证信息
export const submitIdentityInfo = function (data) {
  return api.post(`${domain}api/v2/individual/UpVerify`, {
    data,
    showLoading: true
  })
}

// 获取已推介的朋友数量
export const getInviteUsers = function (data) {
  return api.get(`${domain}api/v5/user/invite/users`, {
    data,
    cache:60
  })
}

// 分发记录
export const getDistributeList = function (data) {
  return api.post(`${domain}api/v2/account2/financesRebate/financesDistributeList/${data.pageSize}/${data.pageNum}`, {
    data:{userId:data.userId},
    cache:false
  })
}

// 我的任务
export const taskInfo = function (data) {
  return api.get(`${domain}api/v5/user/taskInfo`, {
    data
  })
}

// 获取委托记录 - 当前委托、历史委托tp:0，币币成交记录tp:1
export const getCurrentEntrustByParams = function (data) {
  return api.post(`${domain}api/v2/trade/my/queryOrders`, {
    data
  })
}

// 分红记录
export const inviteRecords = function (data) {
  return api.get(`${domain}api/v2/account2/bonusDistributionRecord/inviteCommission/records/${data.page}/${data.size}`, {
  })
}

// 分红记录收益
export const inviteValue = function (data) {
  return api.get(`${domain}api/v2/account2/bonusDistributionRecord/inviteCommission/usdValue`, {
    data
  })
}


/**
 * 获取所有消息/获取所有未读消息
 * @param {*} data {period:String:显示的时间范围, show:Number:每页显示条目, page:Number:当前页码, {}:参数为空时获取所有未读消息}
 */
export const getMessages = function (data) {
  return api.post(`${domain}api/v2/individual/msg`, {
    data,
    cache:60,
    cancel:false,
    showError:false
  })
}

/**
 * 标记单条消息为已读
 * @param {*} data {msg_number:String:消息编号}
 */
export const markItemRead = function (data) {
  return api.post(`${domain}api/v2/individual/readItemMsg`, {
    data,
    cancel:false
  })
}

// 标记所有消息为已读
export const markAllRead = function (data) {
  return api.get(`${domain}api/v2/individual/readAllMsg`, {
    data,
    cache:false,
    showLoading:true
  })
}

// 绑定手机号
export const bindMobile = function (data) {
  return api.post(`${domain}api/v2/individual/bindMobile`, {
    data,
    showLoading:true
  })
}

// 解除手机号
export const unbindMobile = function (data) {
  return api.post(`${domain}api/v2/individual/unbindMobile`, {
    data,
    showLoading:true
  })
}